package com.example.user.controller;


import com.example.user.common.Result;
import com.example.user.entity.Product;
import com.example.user.service.FavoriteService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "http://localhost:8080")
@RequestMapping("/user")
public class FavoriteController {

    @Autowired
    private FavoriteService favoriteService;


    /*
    用户收藏列表展示
     */
    @GetMapping("/selectPage")
    public Result<PageInfo> selectPage(@RequestParam Integer userId, @RequestParam(defaultValue = "1") Integer pageNumber, @RequestParam(defaultValue = "10") Integer pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        List<Product> productList = favoriteService.selectPage(userId);
        return Result.success(new PageInfo(productList));
    }


    /**
     * 取消收藏
     */
    @DeleteMapping("/cancelCollection/{id}")
    public Result cancelCollection(@PathVariable Integer id) {
        Result result = favoriteService.cancelCollection(id);
        return result;
    }


}
